/*
 * Copyright 2008 Lucas Tan.
 * This copyright notice must always remain intact whenever you use or distribute 
 * the source code contained in this file.
 * Any usage of any code in this file, either in derived work or
 * through the use of external linkage,
 * must always be credited with the author's name.
 * 
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 * 
 * */
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;

namespace PassKeeper.Gui
{
	
	/// <summary>
	///     This class is a workaround for a known VS2005 SplitContainer bug.
	///     The designer will set Panel2MinSize before setting the control Size,
	///     and this causes a exception to be thrown. 
	///     The solution used here is to store the Panel2MinSize and set it in after the size is set.
	///     Use this code at your own risk, as I make no warrenty of any kind.
	///     You are free to use this code however you like.
	/// </summary>
	/// <remarks>
	/// This code assumes that the IDE Designer sets SpliiterDistance after
	/// setting the Size
	///</remarks>
	public class SplitContainerFix : SplitContainer
	{
		private int _panel2MinSize;
		private bool _isSized;

		public SplitContainerFix()
		{
			_isSized = false;
			_panel2MinSize = base.Panel2MinSize;
		}

		public new int Panel2MinSize
		{
			get
			{
				if (_isSized)
				{
					return base.Panel2MinSize;
				}
				return _panel2MinSize;
			}
			set
			{

				if (_isSized)
				{
					base.Panel2MinSize = value;
				}
				else
				{
					_panel2MinSize = value;
				}
			}
		}

		public new Size Size
		{
			get
			{
				return base.Size;
			}
			set
			{
				base.Size = value;
				if (!_isSized)
				{
					_isSized = true;
					if (_panel2MinSize > 0)
					{
						base.Panel2MinSize = _panel2MinSize;
					}
				}
			}
		}

	}
	
}
